package com.chanyachting.emall.action.company;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.form.YellowpageForm;
import com.chanyachting.emall.service.CompanyService;
import com.chanyachting.emall.serviceImpl.CompanyServiceImpl;
import com.chanyachting.emall.util.MyFile;
import com.chanyachting.emall.util.RequestUtil;

public class UpdateYellowPageAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		Company company=(Company)ru.getSessionObject(CompanyService.COMPANY_IN_SESSION,new Company()); //从session中获得公司信息
		
		YellowpageForm ypForm=(YellowpageForm)form;
		
		String yellowPageUrl=MyFile.saveFileForm(ypForm.getYellowPageFile(), request);  //上传黄页图片 
		
		if(yellowPageUrl!=null && !yellowPageUrl.equals("")) company.setYellowPageImgUrl(yellowPageUrl);  //设置黄页图片url
		
		company.setYellowPageSummary(ypForm.getYellowPageSummary());  //设置黄页说明
		
		CompanyService cs=new CompanyServiceImpl();
		
		//更新黄页信息
		if(cs.updateCompany(company)){
			
			ru.setSuccessMsg();
		}else{
			
			ru.setFailMsg();
		}
		
		return mapping.findForward("yellowpageUpdate");
	}
	
	

}
